/*
 * Created on 2005-6-20
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.linkage.util.beanutils;

import java.util.Date;

import org.apache.commons.beanutils.ConversionException;

import org.apache.commons.beanutils.Converter;

import com.linkage.util.SystemUtil;

/**
 * @author Administrator
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
@SuppressWarnings("unused")
public final class UtilDateConverter implements Converter {
	/**
     * The default value specified to our Constructor, if any.
     */

	private Object defaultValue = null;


    /**
     * Should we return the default value on conversion errors?
     */
    private boolean useDefault = true;
	/**
	 * 
	 */
	public UtilDateConverter() {
		this.defaultValue = null;
        this.useDefault = false;
		// TODO Auto-generated constructor stub
	}
	public UtilDateConverter(Object defaultValue) {
		this.defaultValue = defaultValue;
	}

	/**
     * Convert the specified input object into an output object of the
     * specified type.
     *
     * @param type Data type to which this value should be converted
     * @param value The input value to be converted
     *
     * @exception ConversionException if conversion cannot be performed
     *  successfully
     */
    @SuppressWarnings("unchecked")
	public Object convert(Class type, Object value) {

        if (value == null) {
            return (Date)null;
        }

        if (value instanceof Date) {
            return (value);
        }
        else
        	if(value instanceof String){
        		return SystemUtil.getDateFromString(SystemUtil.formateDateStringForConvert((String)value));
        	}
        	else
        		return (Date)null;
    }

}
